import axios from '@/utils/http';
import base from './base';

export default {
  // 创建社区
  create(params) {
    return axios.post(
      `${base.sq}/communities`,
      {
        title: params.title,
        description: params.desc,
        avatar_ufile_key: params.avatarKey,
        user_id: params.ownerId,
      },
    );
  },
  // 社区列表
  index(params = {}) {
    return axios.get(
      `${base.sq}/communities`,
      {
        params: {
          type: params.type,
        },
      },
    );
  },
  // 社区展示
  show(params) {
    return axios.get(`${base.sq}/communities/${params.communityId}`);
  },
  update(params) {
    return axios.put(
      `${base.sq}/communities/${params.communityId}`,
      {
        title: params.title,
        description: params.desc,
        avatar_ufile_key: params.avatarKey,
      },
    );
  },
  // 邀请
  invite(params) {
    return axios.post(
      `${base.sq}/communities/${params.communityId}/community_invites`,
      {
        product_ids: params.spacesId,
      },
    );
  },
  // 加载邀请信息
  inviteShow(params) {
    return axios.get(`${base.sq}/communities/${params.communityId}/community_invites/${params.inviteId}`);
  },
  // 社区关联的空间
  spaces(params) {
    return axios.get(
      `${base.sq}/communities/${params.communityId}/products`,
      {
        params: {
          type: params.type,
        },
      },
    );
  },
  // 社区下空间的资源
  docs(params) {
    return axios.get(
      `${base.sq}/communities/${params.communityId}/product_files`,
      {
        params: {
          page: params.page,
        },
      },
    );
  },
  // 社区下空间的问题
  issues(params) {
    return axios.get(
      `${base.sq}/communities/${params.communityId}/issues`,
      {
        params: {
          page: params.page,
        },
      },
    );
  },
};
